﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Prodcrast
{
    public partial class SettingsForm : Form
    {
        /// <summary>
        /// 
        /// </summary>
        public SettingsForm()
        {
            InitializeComponent();

            txtSaveDestination.Text = Properties.Settings.Default.DownloadDirectory;
            chkMaxAtAll.Checked = Properties.Settings.Default.CapAtAll;
            chkMaxPerServer.Checked = Properties.Settings.Default.CapServer;
            numMaxAtAll.Value = Properties.Settings.Default.MaxAtAll;
            numMaxPerServer.Value = Properties.Settings.Default.MaxServer;

            numMaxAtAll.Enabled = chkMaxPerServer.Checked;
            numMaxPerServer.Enabled = chkMaxPerServer.Checked;

            DialogResult = DialogResult.Cancel;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.SelectedPath = txtSaveDestination.Text;

            if (fbd.ShowDialog() == DialogResult.OK)
            {
                txtSaveDestination.Text = fbd.SelectedPath;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        private void Save()
        {
            Properties.Settings.Default.DownloadDirectory = txtSaveDestination.Text;
            Properties.Settings.Default.CapAtAll = chkMaxAtAll.Checked;
            Properties.Settings.Default.CapServer = chkMaxPerServer.Checked;
            Properties.Settings.Default.MaxAtAll = (int)numMaxAtAll.Value;
            Properties.Settings.Default.MaxServer = (int)numMaxPerServer.Value;

            Properties.Settings.Default.Save();
        }

        /// <summary>
        /// 
        /// </summary>
        private void Cancel()
        {
            Close();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;

            Save();
            Close();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkMaxPerServer_CheckedChanged(object sender, EventArgs e)
        {
            numMaxPerServer.Enabled = chkMaxPerServer.Checked;
        }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void chkMaxAtAll_CheckedChanged(object sender, EventArgs e)
        {
            numMaxAtAll.Enabled = chkMaxAtAll.Checked;
        }


    }
}
